<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	UserBean user = (UserBean)request.getSession().getAttribute("userBean");
	
	String _db = user.getDbType();
	Map<String,List<Map<String, String>>> dicMap = user.getDicMap();
	List<Map<String, String>> list = null;
	
	String tbe_nation = "";//民族
	
	list = dicMap.get("5");
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_nation += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>"/>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta http-equiv="pragma" content="no-cache"/>
		<meta http-equiv="cache-control" content="no-cache"/>
		<meta http-equiv="expires" content="0"/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

		<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
		<link type="text/css" rel="stylesheet" href="resource/css/style.css" />

		<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
		<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/validata.js"></script>

		<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerTree.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerForm.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerDateEditor.js"></script>
		
<script type="text/javascript">
var _db = '<%=_db%>';

_jsonObj.classname = "com.wxtf.platform.main.jcqkgl.only_childAction";
_jsonObj.methodname = "";
_jsonObj.logicdata = "[]";

var win;//新建/修改弹出框
var win2;//选人弹出框
var manager;//表格

$(function(){
	manager = $("#emp-grid").ligerGrid({
		url: _url, parms: _jsonObj, width: '100%',height:'100%',heightDiff:-30,
		usePager: true, rownumbers: true, checkbox: true, alternatingRow: true,onAfterShowData: function(data, currentPageData)
		 {
		     //allProps(data);
		     $("#Total").val(data.Total);
		     $("#TotalMon").val(data.TotalMon);
		 },
                columns: [
                { display:'trpocfm_id', name:'trpocfm_id', width:1,hide:true},
                { display:'org_id', name:'org_id', width:1,hide:true},
	            { display: '机构名称', name: 'reserve1', width: 150, align: 'left'},
				{ display: '状态', name: 'reserve2', width: 100, align: 'left',
					render: function (row)
	                {
	                   var html = '';
	                   if(row.reserve2!=''){
	                   		html = '证件已注销';
	                   }else{
                   			var birthday=(parseInt(row.trpocfm_child_birthday.substring(0,4))+18).toString()+row.trpocfm_child_birthday.substring(4);
	                  		var d = new Date();
							var vYear = d.getFullYear();
							var vMon = d.getMonth() + 1;
							var vDay = d.getDate();
                   			var res = compareDate(vYear+"-"+vMon+"-"+vDay,birthday);
							if(null == res || res > 0){
								html = '已满18岁';
							}
	                   }
	                   return html;
	                }
				},
                { display:'tbfi_id', name:'tbfi_id', width:1,hide:true},
                { display:'员工姓名', name:'trpocfm_father_name',align: 'left',width:150,isSort:false,render: function(record, index, value, oth){
						return " <a href='javascript:addData(" + JSON.stringify(record) + ")'>"+value+"</a>";
					}
				},
                { display:'父亲年龄', name:'trpocfm_father_age', width:1,hide: true},
                { display:'父亲工龄', name:'trpocfm_father_seniority', width:1,hide: true},
                { display:'配偶姓名', name:'trpocfm_mother_name',align: 'left',width:150},
                { display:'母亲年龄', name:'trpocfm_mother_age', width:1,hide: true},
                { display:'母亲工龄', name:'trpocfm_mother_seniority', width:1,hide: true},
                { display:'独生子女姓名', name:'trpocfm_child_name',align: 'left',width:150},
                { display:'独生子女出生日期', name:'trpocfm_child_birthday',align: 'left',width:180},
                {
                    display: '独生子女性别', name: 'trpocfm_child_sex',width: 100, 
                    render: function (row)
                    {
                       var html = ' ';
                       if(row.trpocfm_child_sex=='0'){
                       		html = '男';
                       }else if(row.trpocfm_child_sex=='1'){
                       		html = '女';
                       }
                       return html;
                    }
                },
                { display:'独生子女民族', name:'trpocfm_child_nation', width:1,hide:true},
                { display:'独生子女证领取时间', name:'trpocfm_ocr_time',align: 'left',width:180},
                { display: '核算独生子女费标准', name: 'trpocfm_fee_option',width: 180,
                    render: function (row)
                    {
                       var html = ' ';
                       if(row.trpocfm_fee_option=='0'){
                       		html = '五元';
                       }else if(row.trpocfm_fee_option=='1'){
                       		html = '十元';
                       }
                       else if(row.trpocfm_fee_option=='2'){
                       		html = '无';
                       }
                       return html;
                    }
                },
                { display:'发放日期',name:'trpocfm_issue_time',align:'left',width:180},
                { display:'总金额', name:'total',align:'left',width:100,isSort:false},
                { display:'备注', name:'trpocfm_memo',hide:true,width:1},
                { display: 'reserve2', name: 'reserve2', width:  1, hide:true },
				{ display: 'reserve3', name: 'reserve3', width:  1, hide:true },
				{ display: 'reserve4', name: 'reserve4', width:  1, hide:true },
				{ display: 'reserve5', name: 'reserve5', width:  1, hide:true },
				{ display: '录入人', name: 'create_by', width:  1, hide:true },
				{ display: '录入时间', name: 'create_time', width:  1, hide:true },
				{ display: '最后修改人', name: 'last_modify_by', width:  1, hide:true },
				{ display: '最后修改时间', name: 'last_modify_time', width: 1, hide:true },
     			{ display: '编辑', name:'edit',isSort:false,width:60,render: function(record, index, value, oth){
					if(record.reserve2 == ''){
				        var birthday=(parseInt(record.trpocfm_child_birthday.substring(0,4))+18).toString()+record.trpocfm_child_birthday.substring(4);
	                 		var d = new Date();
						var vYear = d.getFullYear();
						var vMon = d.getMonth() + 1;
						var vDay = d.getDate();
	                 			var res = compareDate(vYear+"-"+vMon+"-"+vDay,birthday);
						if(null == res || res > 0){
							return "<img src='ligerUI/skins/icons/search.gif' onclick='addData(" + JSON.stringify(record) + ")'></img>";
						}else
						{
							return "<img src='ligerUI/skins/icons/edit.gif' onclick='addData(" + JSON.stringify(record) + ")'></img>";
						}
					}else{
						return "<img src='ligerUI/skins/icons/search.gif' onclick='addData(" + JSON.stringify(record) + ")'></img>";
					}
				}
			}
		],
		toolbar: {
                	items: [        
		                { text: '删除', click: function(){ delData(); },icon: 'delete'}
	                ]
                }
            });

	
	/*
	 * 日期框
	 */
	$("#trpocfm_child_birthday").ligerDateEditor({ format: "yyyy-MM-dd", width:182 });
	$("#trpocfm_ocr_time").ligerDateEditor({ format: "yyyy-MM-dd", width:182});
	$("#ser4").ligerDateEditor({ format: "yyyy-MM-dd", width:164});
	$("#ser5").ligerDateEditor({ format: "yyyy-MM-dd", width:164});
});

/*
 * 表格刷新
 */
function reload(){
	_jsonObj.methodname = "queryPage";
	_jsonObj.logicdata = "[{\"types\":\"init\"}]";
	manager.loadData();
}

/*
 * ajax成功回调
 */
function ajaxCallbackSuccFunc(data, textStatus){
	serch1();
	if(data.result || data.result == 'true'){
		succMsgTip(data.resultrecord);
	}else{
		warningTip(data.resultrecord);
	}
	if(win && data.result){
		win.hide();
	};
}

/*
 * ajax失败回调
 */
function ajaxCallbackErrorFunc(data, textStatus){
	warningTip(data.resultrecord);
}

/*
 * 获取列表选中的人员ID
 */
function getUserIds(){
	var arrayUsers = manager.getSelecteds();
	if(arrayUsers.length == 0){
		return "";
	} else {
		var text = "";
		for(var i=0; i<arrayUsers.length; i++){
			text += arrayUsers[i].trpocfm_id + ",";
		}
		return text.substring(0, text.length - 1);
	}
}

/*
 * 新增/修改人员
 */
function addData(row){
	document.getElementById('emp-form').reset();
	$("#trpocfm_ocr_time").ligerGetDateEditorManager().setDisabled();
	if(row){
		loadForm("emp-form", row);
		$("#org_id").attr("disabled", true);
	} else {
		$("#trpocfm_id").val('');
	}
	
	var reserve2 = $("#reserve2").val()
	if(reserve2 !="")
	{
		//设置不可用
		if(win2 == null){
			win2 = initWindowByDiv2('empAdd-div', '编辑信息', 600, 300 ,closeWin);
		}else{
			win2 = initWindowByDiv2('empAdd-div', '编辑信息', 600, 300 ,closeWin);
		}
	}
	else
	{
     	var birthday=(parseInt($("#trpocfm_child_birthday").val().substring(0,4))+18).toString()+$("#trpocfm_child_birthday").val().substring(4);
    	var d = new Date();
		var vYear = d.getFullYear();
		var vMon = d.getMonth() + 1;
		var vDay = d.getDate();
        var res = compareDate(vYear+"-"+vMon+"-"+vDay,birthday);
		if(null == res || res > 0){
			win2 = initWindowByDiv2('empAdd-div', '编辑信息', 600, 300 ,closeWin);
		}
		else
		{
			if(win == null){
				win = initWindowByDiv('empAdd-div', '编辑信息', 600, 300,save,closeWin);
			}else{
				win = initWindowByDiv('empAdd-div', '编辑信息', 600, 300,save,closeWin);
			}
		}
	}
}

/*
 * 新建/修改人员信息
 */
function save(){
	var trpocfm_child_name = $("#trpocfm_child_name").val().trim();
	if(!checkIsString(trpocfm_child_name)){
		warningTip("独生子女姓名：必须为字母、数字、下划线、中文组成");
		return;
	}
	if(fucCheckLength(trpocfm_child_name) > 32){
		warningTip("独生子女姓名：不能超过32字符");
		return;
	}
	var time = $("#trpocfm_ocr_time").val();
	var birthday = $("#trpocfm_child_birthday").val();
	if(birthday == ""){
		warningTip('请填写出生日期');
		return;
	}
	if(time == ""){
		warningTip('请填写领证时间');
		return;
	}
	var trpocfm_memo = $("#trpocfm_memo").val();
	if(!checkIsString(trpocfm_memo)){
		warningTip("备注：必须为字母、数字、下划线、中文组成");
		return;
	}
	if(fucCheckLength(trpocfm_memo) > 512){
		warningTip("备注：不能超过512字符");
		return;
	}
	$("#org_id").attr("disabled", false);

	var text = document.getElementById('org_id');
	text = text.options[text.selectedIndex].text.replaceAll('-','');
	$('#reserve1').val(text);
	_jsonObj.logicdata = getForm("emp-form");
	var trpocfm_id = $("#trpocfm_id").val();
	if(trpocfm_id == ''){
		_jsonObj.methodname = "save";
		callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
	} else {
		_jsonObj.methodname = "update";
		callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
	}
}

/*
 * 删除人员
 */
function delData(){
	var userIds = getUserIds();
	if(userIds == ""){
		warningTip('请至少选择一个用户进行操作');
		return;
	}
	$.ligerDialog.confirm('确定要删除选中的数据吗？（删除不可恢复）', function (opt) { 			
		if(opt){
			_jsonObj.methodname = "delete";
			_jsonObj.logicdata = "[{\"ids\":\"" + userIds + "\"}]";
			callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
		}
	});
}

/*
 * 条件导出查询
 */
function expData(){
	var orgIds = $('#org2').val();
	var father_name = $('#ser1').val();
	var mother_name = $('#ser2').val().trim();
	var fee_option = $('#ser3').val().trim();
	var time1 = $('#ser4').val();
	var time2 = $('#ser5').val();
	
	_jsonObj.methodname = "expData";
	_jsonObj.logicdata = '[{\"orgIds\":\"' + orgIds + '\",\"trpocfm_father_name\":\"' + father_name
			+ '\",\"time1\":\"' + time1 + '\",\"time2\":\"' + time2+ '\",\"trpocfm_mother_name\":\"' + mother_name + '\",\"trpocfm_fee_option\":\"' + fee_option +'\"}]';
	
	callserver(_jsonObj, function(data, textStatus){
		if(data.result){
			downloadFile(data.resultrecord);
		} else {
			warningTip(data.resultrecord);
		}
	}, function(data, textStatus){
	});
}

/*
 * 重置-条件查询
 */
function serReset(){
;
	$('#ser3').val('3');
	$('#ser1').val('');
	$('#ser2').val('');
}

/*
 * 条件查询
 */
function serch1(){
	var orgIds = $('#org2').val();
	var trpocfm_fee_option = $('#ser3').val();
	var trpocfm_father_name = $('#ser1').val();
	var trpocfm_mother_name = $('#ser2').val();
	var time1 = $('#ser4').val();
	var time2 = $('#ser5').val();
	
	_jsonObj.methodname = "queryPage";
	_jsonObj.logicdata = '[{\"orgIds\":\"' + orgIds	+ '\",\"trpocfm_fee_option\":\"' + trpocfm_fee_option + '\",\"trpocfm_mother_name\":\"' + trpocfm_mother_name
			 + '\",\"time1\":\"' + time1 + '\",\"time2\":\"' + time2+ '\",\"trpocfm_father_name\":\"' + trpocfm_father_name + '\",\"types\":\"serch1\"}]';
	manager.loadData();
}

/*
 * 时间验证
 */
function joinTime(ele){
	var tbe_work_area = $('#trpocfm_child_birthday').val();
	var tbe_join_time = $('#trpocfm_ocr_time').val();
	if('' != tbe_work_area && '' != tbe_join_time){
		var res = compareDate(tbe_work_area, tbe_join_time);
		if(null == res || res > 0){
			ele.value = '';
			warningTip('办证时间应大于等于出生日期');
			return;
		}
	}
}

</script>
</head>
<body>
	<table id="aaa" class="serTable">
			<tr>
				<td>机构：</td>
				<td><select id="org2" style=" width: 164px;">
						<%=user.getCurSubOrgOptions()%>
					</select>
				</td>
				<td>员工姓名：</td>
				<td><input id="ser1" style=" width: 160px;"/></td>
				<td>配偶姓名：</td>
				<td><input id="ser2" style=" width: 160px;"/></td>
				<td><input class="btn2" value="搜索" type="button" onclick="serch1();" /></td>
			</tr>
			<tr>
			<tr>
				<td>核算标准：</td>
				<td><select id="ser3" style="width: 164px;">
				<option value="3">全部</option>
				<option value="0">五元</option>
				<option value="1">十元</option>
				<option value="2">无</option>
				</select>
				</td>
				<td>领证时间：</td>
				<td><input id="ser4" onkeyup="this.value=formatdata(this.value);"/></td>
				<td>--</td>
				<td><input id="ser5" onkeyup="this.value=formatdata(this.value);"/></td>
				<td><input class="btn2" value="导出" type="button" onclick="expData();" /></td>
			</tr>
		</table>
		
		<div id="emp-grid"></div>
		<div style="font-size: 15px;text-align: left;margin-top: 5px;">总人数
			<input type="text" id="Total" style="border:0;width: 60px;border-bottom: 1px solid #000;text-align: center;"/>人,
			总金额
			<input type="text" id="TotalMon" style="border:0;width: 60px;border-bottom: 1px solid #000;text-align: center;"/>元。
		</div>
		<div id="empAdd-div" style="display: none;">
			<form id="emp-form" name="emp-form">
				<input type="hidden" id="trpocfm_id" name="trpocfm_id" value="" />
				<input type="hidden" id="tbfi_id" name="tbfi_id" value="" />
				<input type="hidden" id="reserve1" name="reserve1" value="" />
				<input type="hidden" id="reserve2" name="reserve2" value="" />
				<input type="hidden" id="reserve3" name="reserve3" value="" />
				<input type="hidden" id="reserve4" name="reserve4" value="" />
				<input type="hidden" id="reserve5" name="reserve5" value="" />
				<input type="hidden" id="create_by" name="create_by" value="" />
				<input type="hidden" id="create_time" name="create_time" value="" />
				<input type="hidden" id="last_modify_by" name="last_modify_by" value="" />
				<input type="hidden" id="last_modify_time" name="last_modify_time" value="" />
				
				<table class="form_table">
					<tr>
						<td colspan="9" align="left">
							<div style="border-bottom: 1px solid #EBEBEB; font-weight:bold;height: 28px; line-height: 28px;margin: 0 0 5px;" >
								<img src="ligerUI/skins/icons/communication.gif"/>
								<span>基础信息</span>
							</div>
						</td>
					</tr>
					<tr>
						<td class="form_label">机构：</td>
						<td>
							<select id="org_id" name="org_id" style=" width: 182px;">
								<%=user.getCurSubOrgOptions()%>
							</select>
						</td>
						<td></td>
						<td class="form_label">子女姓名：</td>
						<td><input class="textbg1" id="trpocfm_child_name" name="trpocfm_child_name" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">出生日期：</td>
						<td><input id="trpocfm_child_birthday" name="trpocfm_child_birthday"  onblur="joinTime(this);" onkeyup="this.value=formatdata(this.value);"/></td>
						<td><font color="red">*</font></td>
						<td class="form_label">子女性别：</td>
						<td align="left" id="trpocfm_child_sex">
							<input style="margin-top: 2px;" type="radio" name="trpocfm_child_sex" value="0" checked="checked" />男
							<input style="margin-top: 2px;" type="radio" name="trpocfm_child_sex" value="1" />女
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">员工姓名</td>
						<td><input class="textbg1" id="trpocfm_father_name" name="trpocfm_father_name" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
						<td class="form_label">配偶姓名：</td>
						<td><input class="textbg1" id="trpocfm_mother_name" name="trpocfm_mother_name" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">民族：</td>
						<td>
							<select id="trpocfm_child_nation" name="trpocfm_child_nation" style=" width: 182px;">
								<%=tbe_nation%>
							</select>
						</td>
						<td></td>
						<td class="form_label">发放日期：</td>
						<td><input class="textbg1" id="trpocfm_issue_time" name="trpocfm_issue_time" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>
					<tr style="display: none;">
						<td class="form_label">员工年龄：</td>
						<td><input class="textbg1" id="trpocfm_father_age" name="trpocfm_father_age" value="0" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
						<td class="form_label">员工工龄：</td>
						<td><input class="textbg1" id="trpocfm_father_seniority" name="trpocfm_father_seniority" value="0"onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>

					<tr style="display: none;">
						<td class="form_label">配偶年龄：</td>
						<td><input class="textbg1" id="trpocfm_mother_age" name="trpocfm_mother_age" value="0" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
						<td class="form_label">配偶工龄：</td>
						<td><input class="textbg1" id="trpocfm_mother_seniority" name="trpocfm_mother_seniority" value="0"onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">核算标准：</td>
						<td>
						<select id="trpocfm_fee_option" name="trpocfm_fee_option" style="width: 182px;">
							<option value="0">五元</option>
							<option value="1">十元</option>
							<option value="2">无</option>
							</select>	
						</td>
						<td><font color="red">*</font></td>
						<td class="form_label">领证时间：</td>
						<td><input id="trpocfm_ocr_time" name="trpocfm_ocr_time" onblur="joinTime(this);" onkeyup="this.value=formatdata(this.value);"/></td>
						<td></td>
						</tr>
					<tr>
						<td class="form_label">备注：</td>
						<td><input class="textbg1" id="trpocfm_memo" name="trpocfm_memo" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>					
					<tr><td><br /></td></tr>
				</table>
			</form>
		</div>
	</body>
</html>